var app = getApp();
Page({
  data: {
	cdnUrl: '',
    isWxapp: true,
    userInfo: {
      id: 0,
      avatar: '/assets/images/avatar.png',
      nickname: '游客',
      balance: 0,
      score: 0,
      level: 0
    },
		/* 自定义导航栏参数 */
		loading: false,
		color: '#FFFFFF',
		background: '#02B3BA',
		show: true,
		animated: false,
		back: true,
		title: "积分商城",
		
		/* 商品列表 */
		productList: []
  },
	/* 获取商品列表 */
	productList: function (){
		var that = this;
		app.request("/addons/cms/wxapp.shop/productList", {}, function (data, ret) {
		  // app.success('头像上传成功!');
		  that.setData({ 
				productList: data,
			});
		}, function (data, ret) {
		  // app.error(ret.msg);
		});
	},
  onLoad: function () {
    var that = this;
    that.setData({
    	cdnUrl: app.cdnUrl,
    });
  },
  onShow: function (e) {
    var that = this;
		that.productList();//获取商品列表信息
    if (app.globalData.userInfo) {
      that.setData({ 
        userInfo: app.globalData.userInfo, 
        // isWxapp: that.isWxapp() 
      });
    }else{
			app.showLoginModal(e);
		}
  },
  login: function () {
    var that = this;
    wx.getUserProfile({
      lang:'zh',
      desc:'授权用户信息',
      success:function(res){
        console.log(res)
        app.login(res.userInfo,function () {
          that.setData({ 
            userInfo: app.globalData.userInfo, 
            // isWxapp: that.isWxapp()
          });
        });
      },
      fail:function(e){
        app.info(JSON.stringify(e));
      }
    })
  },
  
  
  
  
})
